#include <allegro.h>
#include "jardin.h"

void gravity(perso* p,BITMAP * Background)
        {

        (p->y)+=200;
      
        }

//chargement des image
void chargementImage(perso *per)
{
        per->img_right[0]=load_bitmap("1p.bmp",NULL);
        per->img_right[1]=load_bitmap("2p.bmp",NULL);
        per->img_right[2]=load_bitmap("3p.bmp",NULL);
        per->img_right[3]=load_bitmap("4p.bmp",NULL);
        per->img_right[4]=load_bitmap("5p.bmp",NULL);
        per->img_right[5]=load_bitmap("6p.bmp",NULL);
        per->img_right[6]=load_bitmap("7p.bmp",NULL);
        per->img_right[7]=load_bitmap("8p.bmp",NULL);

        

}

void deplacement(perso* per,int *j,int *position, BITMAP *Buffer,BITMAP *Background, BITMAP *Image_j, BITMAP *obstacle11, BITMAP *obstacle22, BITMAP *obstacle33)
{

//Background = load_bitmap("garden2.bmp", NULL);	
//les positions des obstacles
	int o=850,k=1400,m=2000,p=2800,a=3200,b=4000;
	int oo=400,kk=400,mm=400,pp=450,aa=400,bb=450;
*position-=20;
if (*position==-5600)
{*position=0;}

	if((*j)==7) {(*j)=0;}
	//Image_j=per->img_right[3];
	//blit(Background, Buffer, *position, 0,0 , 0, Background->w, Background->h);
        usleep(50000);
       // draw_sprite(Buffer,Image_j,per->x,per->y);
        (*j)++;
          if (per->y!=200)
        {
        	gravity(per,Background);
        	
        }  
       
        	draw_sprite(Background,obstacle22,o,oo);
        	o-=20;
              
        	draw_sprite(Background,obstacle11,k,kk);
        	k-=20;
                       
        	draw_sprite(Background,obstacle22,m,mm);
        	m-=20;
                
               	draw_sprite(Background,obstacle33,p,pp);
        	p-=20;
        	
        	draw_sprite(Background,obstacle11,a,aa);
        	a-=20;
       
       		draw_sprite(Background,obstacle33,b,bb);
        	b-=20;  
        
        if ( per->y == 200 && *position <= -800  )
        {	
        	*position = 0;
        }
        
       // blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
        
        if (key[KEY_SPACE] )
        {
        	per->y-=200;
        	
        }
        
      
        
o=850;
k=1400;
m=2000;
p=2800;
a=3200;
b=4000;
}
